<?php
	include_once('cgi/function.php');
	$appid = '100693478';
	$format = 'json';
	$openid = getRequest('openid');
	//$openid = '1B80113F03C13FE09F8B303C95A55ABA';
	$openkey = getRequest('openkey');
	//$openkey = 'C6AFCCF74EAB238B967FF5DCDCAA5383';
	$pf = getRequest('pf');
	//$pf = 'qzone';
	$useip = getIp();
	//$useip = '121.14.98.46';
	$app_host = 'http://openapi.tencentyun.com/v3/user/get_info?';// 正式环境：http://119.147.19.43/v3/user/get_info?

	$get_url = rawurlencode('/v3/user/get_info');
	$prams = rawurlencode('appid='.$appid.'&format=json&openid='.$openid.'&openkey='.$openkey.'&pf='.$pf.'&userip='.$useip);
	$step1 = 'GET&'.$get_url.'&'.$prams;
	$step2 = '14ee5de4d2bd5e9b73215fbbdffa4feb&';
	
	$hash_hmac = hash_hmac('sha1',$step1,$step2,true);
	$sig = rawurlencode(base64_encode($hash_hmac));
	
	$qq_get_url = $app_host;
	$prams = 'openid='.$openid.'&openkey='.$openkey.'&appid='.$appid.'&sig='.$sig.'&pf='.$pf.'&format='.$format.'&userip='.$useip;
	
	$qq_get_url .=$prams;
	$userinfo = json_decode(Curl_Curl::get($qq_get_url),true);
	if((!isset($_COOKIE['user_unid_13dao']) || $_COOKIE['user_unid_13dao']!=$openid) && $userinfo['ret']===0){//接口返回正确将信息写入本地数据库
		$db = DB_Sqlite2::initialize();
		$insert = "insert into userinfo (qq_nickname,qq_gender,qq_figureurl,qq_openid) values('".iconv('utf-8','gbk',$userinfo['nickname'])."','".iconv('utf-8','gbk',$userinfo['gender'])."','{$userinfo['figureurl']}','{$openid}');";
		if(!$db->query($insert)){
			Log_Log::write('用户信息入库失败，错误信息：'.$db->getLastError().'请求串：'.json_encode($userinfo));
		}
		setcookie('user_unid_13dao',$openid,time()+3600<<20,'/',getdomain());
	}
	$uname = isset($userinfo['nickname'])?$userinfo['nickname']:'error';
	$uimage = isset($userinfo['figureurl'])?$userinfo['figureurl']:'static/images/init.jpg';
	$allGamers = array(
					'0'=>array('name'=>'黄歇','image'=>'http://thirdapp0.qlogo.cn/qzopenapp/27a87a80731bf0f8c47924a775821396fb5d5310de890ed9e7b1b0089344267d/50'),
					'1'=>array('name'=>'∮流行→断/raby','image'=>'http://thirdapp1.qlogo.cn/qzopenapp/3b9a4bbcdd70c70351d0ab26d8824c2a540bb902ab83c9459bdf6d31b5b7d00b/50'),
					'2'=>array('name'=>'oh!no','image'=>'http://thirdapp0.qlogo.cn/qzopenapp/9a39e278ce662d4699ad57ccf54b4ad81d89ee9272487636558917443f4d4c86/50'),
					'3'=>array('name'=>$uname,'image'=>$uimage,'oid'=>$openid)
				);
	$retScript = getThisOrder($allGamers,3);
	echo '<script>var GAMER_LIST_INFO='.$retScript.'</script>';
?>